{include file="public/header"}
<body>
<div id="app">
    <div class="ht-main">
        <div class="ht-main-body">
            <el-form label-width="80px" :model="admin" size="small">
                <el-form-item label="登录名">
                    <el-input placeholder="登录名" v-model="admin.user_name" :disabled="{:session('admin.auth_group_id')} !== 1 "></el-input>
                </el-form-item>
                <el-form-item label="用户组">
                    <el-select style="width: 100%;" v-model="admin.auth_group_id" :disabled="{:session('admin.auth_group_id')} !== 1  ">
                        <el-option v-for="(item,index) in user_group" :value="item.id" :key="index" :label="item.title"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="手机">
                    <el-input placeholder="手机" v-model="admin.phone"></el-input>
                </el-form-item>
                <el-form-item label="姓名">
                    <el-input placeholder="姓名" v-model="admin.real_name"></el-input>
                </el-form-item>
                <el-form-item label="二维码">
                    <el-input placeholder="二维码" v-model="admin.qrcode" style="width: 70%"></el-input>
                    <ht-upload @success="success"></ht-upload>
                </el-form-item>
                <el-form-item v-if="admin.qrcode">
                    <img :src="admin.qrcode" class="ht-image100" @click="showImg(admin.qrcode)">
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" size="mini" @click="onSubmit">提交</el-button>
                    <el-button type="primary" size="mini" @click="refresh">刷新权限</el-button>
                </el-form-item>
            </el-form>
        </div>

    </div>
</div>
{include file="public/common"}
<script>
    let vs
    var vm = new Vue({
        el:"#app",
        data:function () {
            return {
                tableData: [],
                page:1,
                total:1,
                pageSize:15,
                is_edit:false,
                admin:{
                    "real_name":'',
                    "email":'',
                    "phone":'',
                    "username":'',
                    "auth_group_id":'',
                    "user_name":''
                },
                user_group:[],
            }
        },
        created() {
            vs = this
            this.getUserGroup()
            this.getAdminInfo()
        },
        methods: {
            success(path){
                console.log("pathaaaa",path)
                vs.$set(vs.admin,"qrcode",path)
            },
            handleSizeChange(e) {
                this.pageSize = e
            },
            handleCurrentChange(e) {
                this.page = e
            },
            onSubmit() {
                var that = this
                axios.post("{:url('Admin/adminModify')}",this.admin).then((res)=>{
                    if (res.data.code == 1) {
                        this.$message({
                            message:'操作成功',
                            type:'success',
                            duration:1000,
                            onClose:function (){
                                that.is_edit = false
                                location.reload()
                            }
                        })
                    }
                })
            },
            refresh() {
                var that = this
                $.post("{:url('Index/refresh')}",function (res){
                    if (res.code == 1) {
                        that.showSuccessMsgCall(function (){
                            $.ajax({
                                url:'/admin/admin/getUserAuth',
                                dataType:'json',
                                async:false,
                                success:function (res) {
                                    if (res.code === 1) {
                                        sessionStorage.setItem('ht_admin_rule',res.data.auth)
                                    }
                                }
                            })
                        })
                        parent.vm.getMenu()
                    }
                })
            },
            getUserGroup() {
                var that = this
                axios.post('{:url("Ajax/getAdminGroup")}').then((res)=>{
                    that.user_group = res.data.data
                })
            },
            getAdminInfo() {
                var that = this
                axios.post('{:url("Ajax/getAdminInfo")}').then((res)=>{
                    that.admin = res.data.data
                })
            },
            add(){
                this.is_edit = true
                this.content = '添加'
                this.editData = this.editDataTemp
            },
            edit(data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data
                console.log(data)
            },
            goBack(){
                this.is_edit = false
            },
            del(data) {
                var that = this
                that.$confirm('确定删除么?','提示',{
                    type:'warning',
                    lockScroll:false
                }).then(()=>{
                    axios.post('{:url("Ming/MingLiDel")}',{id:data.id}).then((res)=>{
                        let result = res.data;
                        if (result.code === 1) {
                            that.$message({
                                message:'操作成功',
                                type:'success',
                                duration:1000,
                                onClose:function () {
                                    window.location.reload()
                                }
                            })
                        } else {
                            that.showErrorMsg(result.msg)
                        }
                    })
                })
            },
        },
        watch: {
            pageSize(v) {
                this.getData()
            },
            page(v) {
                this.getData()
            }
        }
    })
</script>
</body>
</html>